#include <sys_config.h>

#ifdef DVR_PVR_SUPPORT

#include <types.h>
#include <osal/osal.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#include <hld/hld_dev.h>

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"

#include "string.id"
#include "images.id"
#include "osd_config.h"
#include "osd_rsc.h"

#include "copper_common/system_data.h"
#include "copper_common/menu_api.h"
#include "win_com_menu_define.h"
#include "win_com.h"

#include <hld/dmx/dmx_dev.h>
#include <hld/dmx/dmx.h>
#include <hld/decv/vdec_driver.h>

#include "menus_root.h"
#include "win_com_popup.h"

/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER g_win_pvr_setting;

extern CONTAINER pvr_setting_item_con1;
extern CONTAINER pvr_setting_item_con2;
extern CONTAINER pvr_setting_item_con3;
extern CONTAINER pvr_setting_item_con4;
extern CONTAINER pvr_setting_item_con5;
extern CONTAINER pvr_setting_item_con6;
extern CONTAINER pvr_setting_item_con7;
extern CONTAINER pvr_setting_item_con8;

extern TEXT_FIELD pvr_setting_item_txtname1;
extern TEXT_FIELD pvr_setting_item_txtname2;
extern TEXT_FIELD pvr_setting_item_txtname3;
extern TEXT_FIELD pvr_setting_item_txtname4;
extern TEXT_FIELD pvr_setting_item_txtname5;
extern TEXT_FIELD pvr_setting_item_txtname6;
extern TEXT_FIELD pvr_setting_item_txtname7;
extern TEXT_FIELD pvr_setting_item_txtname8;

extern TEXT_FIELD pvr_setting_item_txtset1;
extern TEXT_FIELD pvr_setting_item_txtset2;
extern TEXT_FIELD pvr_setting_item_txtset3;
extern TEXT_FIELD pvr_setting_item_txtset4;
extern TEXT_FIELD pvr_setting_item_txtset5;
extern TEXT_FIELD pvr_setting_item_txtset6;
extern TEXT_FIELD pvr_setting_item_txtset7;
extern TEXT_FIELD pvr_setting_item_txtset8;

extern TEXT_FIELD pvr_setting_item_line1;
extern TEXT_FIELD pvr_setting_item_line2;
extern TEXT_FIELD pvr_setting_item_line3;
extern TEXT_FIELD pvr_setting_item_line4;
extern TEXT_FIELD pvr_setting_item_line5;
extern TEXT_FIELD pvr_setting_item_line6;
extern TEXT_FIELD pvr_setting_item_line7;
extern TEXT_FIELD pvr_setting_item_line8;


static VACTION pvr_setting_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT pvr_setting_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION pvr_setting_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT pvr_setting_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    pvr_setting_item_con_keymap,pvr_setting_item_con_callback,  \
    conobj, focusID,1)

#define LDEF_TXTNAME(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTN_SH_IDX,TXTN_HL_IDX,TXTN_SL_IDX,TXTN_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

#define LDEF_TXTSET(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTS_SH_IDX,TXTS_HL_IDX,TXTS_SL_IDX,TXTS_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 20,0,resID,str)


#define LDEF_MM_ITEM(root,varCon,nxtObj,varTxtName,varTxtset, varLine,ID,IDu,IDd,l,t,w,h,nameID,setstr)	\
	LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxtName,1)	\
	LDEF_TXTNAME(&varCon,varTxtName,&varTxtset,0,0,0,0,0,l + TXTN_L_OF, t + TXTN_T_OF,TXTN_W,TXTN_H,nameID,NULL)	\
	LDEF_TXTSET(&varCon,varTxtset,  NULL/*&varLine*/        ,1,1,1,1,1,l + TXTS_L_OF, t + TXTS_T_OF,TXTS_W,TXTS_H,0,setstr)	\
	LDEF_LINE(&varCon, varLine, NULL, 1, 1, 1, 1, 1, l + LINE_L_OF, t + CON_H, LINE_W, LINE_H, 0, 0)
/*
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con1, &pvr_setting_item_con2,pvr_setting_item_txtname1,pvr_setting_item_txtset1,pvr_setting_item_line1,1,8,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_DVR_TIMESHIFT,display_strs[0])
*/
    // Gavim@20141021 
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con1, &pvr_setting_item_con2,pvr_setting_item_txtname1,pvr_setting_item_txtset1,pvr_setting_item_line1,1,8,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_DVR_TIMESHIFT,NULL)
								
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con2, &pvr_setting_item_con3,pvr_setting_item_txtname2,pvr_setting_item_txtset2,pvr_setting_item_line2,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	RS_DVR_JUMP,display_strs[1])
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con3, &pvr_setting_item_con4,pvr_setting_item_txtname3,pvr_setting_item_txtset3,pvr_setting_item_line3,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	RS_REC_AS_SCRAMBLED,display_strs[2])
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con4, &pvr_setting_item_con5,pvr_setting_item_txtname4,pvr_setting_item_txtset4,pvr_setting_item_line4,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	RS_TS_FILE_SIZE,display_strs[3])
/*				
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con5, &pvr_setting_item_con6,pvr_setting_item_txtname5,pvr_setting_item_txtset5,pvr_setting_item_line5,5,4,6,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	RS_TMS_TO_REC,display_strs[4])
*/
    // Gavim@20141021 
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con5, &pvr_setting_item_con6,pvr_setting_item_txtname5,pvr_setting_item_txtset5,pvr_setting_item_line5,5,4,6,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	RS_TMS_TO_REC,NULL)
				
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con6, &pvr_setting_item_con7,pvr_setting_item_txtname6,pvr_setting_item_txtset6,pvr_setting_item_line6,6,5,7,	\
				CON_L, CON_T + (CON_H + CON_GAP)*5,CON_W,CON_H,	RS_POPUP_SUBTITLE_ON,display_strs[5])
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con7, &pvr_setting_item_con8,pvr_setting_item_txtname7,pvr_setting_item_txtset7,pvr_setting_item_line7,7,6,8,	\
				CON_L, CON_T + (CON_H + CON_GAP)*6,CON_W,CON_H,	RS_REC_NUM,display_strs[6])
/*
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con8, NULL,pvr_setting_item_txtname8,pvr_setting_item_txtset8,pvr_setting_item_line8,8,7,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	RS_REC_PS_ENABLE,display_strs[7])
*/
    // Gavim@20141021 
LDEF_MM_ITEM(g_win_pvr_setting,pvr_setting_item_con8, NULL,pvr_setting_item_txtname8,pvr_setting_item_txtset8,pvr_setting_item_line8,8,7,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*7,CON_W,CON_H,	RS_REC_PS_ENABLE,NULL)
DEF_CONTAINER(g_win_pvr_setting,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    pvr_setting_con_keymap,pvr_setting_con_callback,  \
    (POBJECT_HEAD)&pvr_setting_item_con1, 1,0)


/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/
#define MENU_PVR_SETTING_TIMESHIFT		1
#define MENU_PVR_SETTING_JUMP			2
#define MENU_PVR_SETTING_SCRAMBLE_MODE	3
#define MENU_PVR_SETTING_TS_FILE_SIZE	4
#define MENU_PVR_SETTING_TMS_2_REC		5
#define MENU_PVR_SETTING_TTX_SUBT		6
#define MENU_PVR_SETTING_REC_NUM		7
#define MENU_PVR_SETTING_REC_PS			8

CONTAINER* pvr_setting_items[] =
{
	&pvr_setting_item_con1,
	&pvr_setting_item_con2,
	&pvr_setting_item_con3,
	&pvr_setting_item_con4,
	&pvr_setting_item_con5,
	&pvr_setting_item_con6,
	&pvr_setting_item_con7,
	&pvr_setting_item_con8,
};

POBJECT_HEAD pvr_setting_item_name[] =
{
	(POBJECT_HEAD)&pvr_setting_item_txtname1,
	(POBJECT_HEAD)&pvr_setting_item_txtname2,
	(POBJECT_HEAD)&pvr_setting_item_txtname3,
	(POBJECT_HEAD)&pvr_setting_item_txtname4,
	(POBJECT_HEAD)&pvr_setting_item_txtname5,
	(POBJECT_HEAD)&pvr_setting_item_txtname6,
	(POBJECT_HEAD)&pvr_setting_item_txtname7,
	(POBJECT_HEAD)&pvr_setting_item_txtname8,
};

POBJECT_HEAD pvr_setting_item_set[] =
{
	(POBJECT_HEAD)&pvr_setting_item_txtset1,
	(POBJECT_HEAD)&pvr_setting_item_txtset2,
	(POBJECT_HEAD)&pvr_setting_item_txtset3,
	(POBJECT_HEAD)&pvr_setting_item_txtset4,
	(POBJECT_HEAD)&pvr_setting_item_txtset5,
	(POBJECT_HEAD)&pvr_setting_item_txtset6,
	(POBJECT_HEAD)&pvr_setting_item_txtset7,
	(POBJECT_HEAD)&pvr_setting_item_txtset8,
};

    // Gavim@20141021 
void win_pvr_set_on_off_string(UINT8 input, PTEXT_FIELD ptxt)
{
	if(input==0)
		OSD_SetTextFieldContent(ptxt, STRING_ID,RS_COMMON_OFF);				
	else
		OSD_SetTextFieldContent(ptxt, STRING_ID,RS_COMMON_ON);	
}

void win_pvr_setting_timeshift_set_string(UINT8 input)
{
//	UINT8 temp[10];

//	sprintf(temp, "%s", (input ? "ON" : "OFF"));
//	ComAscStr2Uni(temp, display_strs[0]);

    // Gavim@20141021 
	win_pvr_set_on_off_string( input ,&pvr_setting_item_txtset1);

}


void win_pvr_setting_jumpstep_set_string(UINT8 input)
{
	UINT8 temp[10];
	
	switch(input)
	{
		case 0:
			sprintf(temp, "30 sec", input);
			break;
		case 1:
			sprintf(temp, "1 min", input);
			break;
		case 2:
			sprintf(temp, "5 min", input);
			break;
		case 3:
			sprintf(temp, "10 min", input);
			break;
		case 4:
			sprintf(temp, "30 min", input);
			break;
		default:
			break;			
	}
	ComAscStr2Uni(temp, display_strs[1]);
}

void win_pvr_setting_scramble_record_mode_set_string(UINT8 input)
{
	UINT8 temp[10];

	sprintf(temp, "%s", (input ? "NO" : "YES"));
	ComAscStr2Uni(temp, display_strs[2]);
}

void win_pvr_setting_ts_file_size_set_string(UINT8 input)
{
	UINT8 temp[10];
	
	switch(input)
	{
		case 0:
			sprintf(temp, "1 G", input);
			break;
		case 1:
			sprintf(temp, "2 G", input);
			break;
		case 2:
			sprintf(temp, "3 G", input);
			break;
		case 3:
			sprintf(temp, "4 G", input);
			break;
		default:
			break;			
	}
	ComAscStr2Uni(temp, display_strs[3]);
}

void win_pvr_setting_tms2rec_set_string(UINT8 input)
{
//	UINT8 temp[10];

//	sprintf(temp, "%s", (input ? "ON" : "OFF"));
//	ComAscStr2Uni(temp, display_strs[4]);

    // Gavim@20141021 
	win_pvr_set_on_off_string( input ,&pvr_setting_item_txtset5);
}

void win_pvr_setting_ttx_subt_set_string(BOOL input)
{
	UINT8 temp[10];

	sprintf(temp, "%s", (input ? "YES" : "NO"));
	ComAscStr2Uni(temp, display_strs[5]);
}

void win_pvr_setting_rec_num_set_string(UINT8 input)
{
	UINT8 temp[10];

	sprintf(temp, "%d", input);
	ComAscStr2Uni(temp, display_strs[6]);
}

void win_pvr_setting_record_ps_set_string(UINT8 input)
{
//	UINT8 temp[10];

//	sprintf(temp, "%s", (input ? "ON" : "OFF"));
//	ComAscStr2Uni(temp, display_strs[7]);

    // Gavim@20141021 
	win_pvr_set_on_off_string( input ,&pvr_setting_item_txtset8);
	
}

void win_pvr_setting_left_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 input;
	struct dvr_HDD_info hdd_info;	
	
	switch(id)
	{
		case MENU_PVR_SETTING_TIMESHIFT:
			sys_data_set_tms(!sys_data_get_tms());
			win_pvr_setting_timeshift_set_string(sys_data_get_tms());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			if (sys_data_get_tms())
			{
				pvr_r_set_record_all(FALSE);//if TMS on, close TP record.
				api_pvr_adjust_tms_space();
				/*
				if (pvr_get_HDD_info(&hdd_info) && (hdd_info.tms_size == 0))
				{
					pvr_set_tms_size(hdd_info.free_size);  // set free space to tms
					pvr_get_HDD_info(&hdd_info);
				}
				*/
			}
			else
			{
				pvr_set_tms_size(0);
			}
			
			pvr_get_HDD_info(&hdd_info);
			api_pvr_check_level(&hdd_info);
			break;
		case MENU_PVR_SETTING_JUMP:
			input = sys_data_get_jumpstep();	
			if(!input)
				input = 5;
			input = (input-1)%5;
			sys_data_set_jumpstep(input);
			win_pvr_setting_jumpstep_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_SCRAMBLE_MODE:
			input = sys_data_get_scramble_record_mode();	
			input = !input;
			sys_data_set_scramble_record_mode(input);
			pvr_r_set_scramble_ext(!input);
			win_pvr_setting_scramble_record_mode_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TS_FILE_SIZE:
			input = sys_data_get_record_ts_file_size();	
			if(!input)
				input = 4;
			input = (input-1)%4;
			sys_data_set_record_ts_file_size(input);
			win_pvr_setting_ts_file_size_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TMS_2_REC:
			sys_data_set_tms2rec(!sys_data_get_tms2rec());
			win_pvr_setting_tms2rec_set_string(sys_data_get_tms2rec());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TTX_SUBT:
			input = sys_data_get_record_ttx_subt();	
			input = !input;
			sys_data_set_record_ttx_subt(input);
			win_pvr_setting_ttx_subt_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_REC_NUM:
			sys_data_set_rec_num(3 - sys_data_get_rec_num());
			win_pvr_setting_rec_num_set_string(sys_data_get_rec_num());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_REC_PS:
			sys_data_set_rec_ps(!sys_data_get_rec_ps());
			win_pvr_setting_record_ps_set_string(sys_data_get_rec_ps());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		default:
			break;
	}
}

void win_pvr_setting_right_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 input;
	struct dvr_HDD_info hdd_info;	
	
	switch(id)
	{
		case MENU_PVR_SETTING_TIMESHIFT:
			sys_data_set_tms(!sys_data_get_tms());
			win_pvr_setting_timeshift_set_string(sys_data_get_tms());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			if (sys_data_get_tms())
			{
				pvr_r_set_record_all(FALSE);//if TMS on, close TP record.
				api_pvr_adjust_tms_space();
				/*
				if (pvr_get_HDD_info(&hdd_info) && (hdd_info.tms_size == 0))
				{
					pvr_set_tms_size(hdd_info.free_size); // set free space to tms
					pvr_get_HDD_info(&hdd_info);
				}
				*/
			}
			else
			{
				pvr_set_tms_size(0);
			}
			pvr_get_HDD_info(&hdd_info);
			api_pvr_check_level(&hdd_info);
			break;
		case MENU_PVR_SETTING_JUMP:
			input = sys_data_get_jumpstep();	
			input = (input+1)%5;
			sys_data_set_jumpstep(input);
			win_pvr_setting_jumpstep_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_SCRAMBLE_MODE:
			input = sys_data_get_scramble_record_mode();	
			input = !input;
			sys_data_set_scramble_record_mode(input);
			pvr_r_set_scramble_ext(!input);
			win_pvr_setting_scramble_record_mode_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TS_FILE_SIZE:
			input = sys_data_get_record_ts_file_size();	
			input = (input+1)%4;
			sys_data_set_record_ts_file_size(input);
			win_pvr_setting_ts_file_size_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TMS_2_REC:
			sys_data_set_tms2rec(!sys_data_get_tms2rec());
			win_pvr_setting_tms2rec_set_string(sys_data_get_tms2rec());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_TTX_SUBT:
			input = sys_data_get_record_ttx_subt();	
			input = !input;
			sys_data_set_record_ttx_subt(input);
			win_pvr_setting_ttx_subt_set_string(input);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_REC_NUM:
			sys_data_set_rec_num(3 - sys_data_get_rec_num());
			win_pvr_setting_rec_num_set_string(sys_data_get_rec_num());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PVR_SETTING_REC_PS:
			sys_data_set_rec_ps(!sys_data_get_rec_ps());
			win_pvr_setting_record_ps_set_string(sys_data_get_rec_ps());
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		default:
			break;
	}
}

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static VACTION pvr_setting_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;		
	case V_KEY_LEFT:		
		act = VACT_DECREASE;
		break;
	case V_KEY_ENTER:
		act = VACT_ENTER;        
        break;
	default:	
		act = VACT_PASS;
		break;
	}

	return act;

}

static PRESULT pvr_setting_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	BOOL	input;
	UINT8	id = OSD_GetObjID(pObj);

	switch(event)
	{		
	case EVN_FOCUS_PRE_GET:
		break;		
	case EVN_FOCUS_PRE_LOSE:
		break;
	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_DECREASE)
		{
			win_pvr_setting_left_key(pObj,id);
		}
		else if(unact == VACT_INCREASE)
		{
			win_pvr_setting_right_key(pObj,id);
		}
		ret = PROC_LOOP;
		break;
	}
	return ret;

}

#define VACT_RECORD_ALL     (VACT_PASS+1)
static VACTION pvr_setting_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
		case V_KEY_UP:
			act = VACT_CURSOR_UP;
			break;			
		case V_KEY_DOWN:
			act = VACT_CURSOR_DOWN;
			break;					
		case V_KEY_EXIT:
		case V_KEY_MENU:
			act = VACT_CLOSE;
			break;
        case V_KEY_RECORD:
            act = VACT_RECORD_ALL;
            break;
//		case V_KEY_ENTER:
//			act = VACT_ENTER;
//			break;
		default:	
			act = VACT_PASS;
			break;
	}

	return act;
}

static PRESULT pvr_setting_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact;
	UINT32 i;
	BOOL subt_flag;
	CONTAINER* cont = (CONTAINER*)pObj;
	UINT8	id = OSD_GetObjID(pObj);
	static UINT8 preval;
	SYSTEM_DATA* p_sys_data;
	
	switch(event)
	{
		case EVN_PRE_OPEN:
			wincom_open_title((POBJECT_HEAD)&win_osdset_con, RS_PVR_SETTING, 0);
			p_sys_data=sys_data_get();
			win_pvr_setting_timeshift_set_string(p_sys_data->timeshift);
			win_pvr_setting_jumpstep_set_string(p_sys_data->jumpstep);
			win_pvr_setting_scramble_record_mode_set_string(p_sys_data->scramble_record_mode);
            remove_menu_item(&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con3, CON_H + CON_GAP);
			win_pvr_setting_ts_file_size_set_string(p_sys_data->record_ts_file_size);
			remove_menu_item(&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con4, CON_H + CON_GAP);
			win_pvr_setting_tms2rec_set_string(p_sys_data->tms2rec);			
			win_pvr_setting_ttx_subt_set_string(p_sys_data->record_ttx_subt);
#ifdef _INVW_JUICE
			remove_menu_item(&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con5, CON_H + CON_GAP);
#endif
			remove_menu_item(&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con6, CON_H + CON_GAP);
			win_pvr_setting_rec_num_set_string(p_sys_data->rec_num);
			remove_menu_item(&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con7, CON_H + CON_GAP);
#ifdef NEW_DEMO_FRAME
			win_pvr_setting_record_ps_set_string(p_sys_data->rec_ps_enable);
	#if defined( SUPPORT_CAS9) || defined( SUPPORT_CAS7) ||defined (SUPPORT_VMX_STD) ||defined (SUPPORT_VMX) ||defined(FTA_ONLY) || defined(VMX_PVR_SUPPORT)
			#ifndef SUPPORT_TMS2REC // @HM_CONAX3515
			remove_menu_item((POBJECT_HEAD)&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con5, CON_H + CON_GAP);
			#endif
			remove_menu_item((POBJECT_HEAD)&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con8, CON_H + CON_GAP);
	#endif
#else
			remove_menu_item((POBJECT_HEAD)&g_win_pvr_setting, (OBJECT_HEAD *)&pvr_setting_item_con8, CON_H + CON_GAP);
#endif
			break;
		case EVN_POST_OPEN:
			break;			
		case EVN_PRE_CLOSE:
       		*((UINT32 *)param2) &= ~C_CLOSE_CLRBACK_FLG;
			p_sys_data=sys_data_get();
			sys_data_save(1);
#ifndef PVR3_SUPPORT
			pvr_r_set_ts_file_size(p_sys_data->record_ts_file_size + 1);
#endif
			//api_pvr_jumpstep_trans();
			break;
		case EVN_POST_CLOSE:
			break;
        case EVN_UNKNOWN_ACTION:
            if (api_pvr_is_record_active())
                break;
            
            win_popup_choice_t choice;
            UINT8 back_saved;

#if (!defined(CI_PLUS_PVR_SUPPORT) && !defined(CAS9_PVR_SUPPORT)&&!defined(CAS7_PVR_SUPPORT) && !defined(CAS9_PVR_SCRAMBLED) &&!defined(VMX_PVR_STD_SUPPORT) &&!defined(VMX_PVR_SUPPORT))
			if (sys_data_get_tms() == 0)
			{
				win_popup_choice_t choice;
				UINT8 back_saved;			
				win_compopup_init(WIN_POPUP_TYPE_OKNO);
				win_compopup_set_msg("Are you sure to enter record TP mode?", NULL, 0);
				if (pvr_r_get_record_all())
					win_compopup_set_default_choice(WIN_POP_CHOICE_YES);
				else
					win_compopup_set_default_choice(WIN_POP_CHOICE_NO);
				choice = win_compopup_open_ext(&back_saved);
				if(choice == WIN_POP_CHOICE_YES)
				{
					pvr_r_set_record_all(TRUE);
				}	
				else if (choice == WIN_POP_CHOICE_NO)
				{
					pvr_r_set_record_all(FALSE);
				}
			
			}
			else
#endif
#if (!(defined(CAS9_PVR_SUPPORT)||defined(CAS7_PVR_SUPPORT) || defined(CAS9_PVR_SCRAMBLED)||defined(VMX_PVR_STD_SUPPORT)||defined(VMX_PVR_SUPPORT)))
			{
	            win_compopup_init(WIN_POPUP_TYPE_OKNO);
	            win_compopup_set_msg("Record CA program in descrambled format?", NULL, 0);
	            if (sys_data_get_scramble_record_mode())
	                win_compopup_set_default_choice(WIN_POP_CHOICE_YES);
	            else
	                win_compopup_set_default_choice(WIN_POP_CHOICE_NO);
	            choice = win_compopup_open_ext(&back_saved);
	            if (choice == WIN_POP_CHOICE_YES)
	            {
	                sys_data_set_scramble_record_mode(1);
	                pvr_r_set_scramble_ext(0);
	            }
	            else if (choice == WIN_POP_CHOICE_NO)
	            {
	                sys_data_set_scramble_record_mode(0);
	                pvr_r_set_scramble_ext(1);
	            }
			}
#endif
            break;
	}
	
	return ret;
}

#endif//#ifdef DVR_PVR_SUPPORT
